package com.example.qihuibao.widget.dialog

import android.text.Editable
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import com.example.qihuibao.R
import com.example.qihuibao.base.BaseDialogFragment

/**
 *@author: cww
 *@desc:修改单个值的对话框
 *@date: 5/16/23 10:58 AM
 */
class ChooseServerUrlDialog(val title:String="", val default:String="", val valueBack:(value:String)->Unit) : BaseDialogFragment(R.layout.dialog_choose_serverurl) {

    private var etServerUrl:EditText? = null
    private var tvServerUrl1:TextView? = null
    private var tvServerUrl2:TextView? = null
    private var tvServerUrl3:TextView? = null

    override fun initView() {
        mView?.findViewById<TextView>(R.id.tv_title)?.text = title
        etServerUrl = mView?.findViewById(R.id.et_value)
        tvServerUrl1 = mView?.findViewById(R.id.tv_server_url1)
        tvServerUrl2 = mView?.findViewById(R.id.tv_server_url2)
        tvServerUrl3 = mView?.findViewById(R.id.tv_server_url3)
        etServerUrl?.text = Editable.Factory.getInstance().newEditable(default)
        tvServerUrl1?.setOnClickListener {
            etServerUrl?.text = Editable.Factory.getInstance().newEditable(tvServerUrl1!!.text)
        }
        tvServerUrl2?.setOnClickListener {
            etServerUrl?.text = Editable.Factory.getInstance().newEditable(tvServerUrl2!!.text)
        }
        tvServerUrl3?.setOnClickListener {
            etServerUrl?.text = Editable.Factory.getInstance().newEditable(tvServerUrl3!!.text)
        }
        mView?.findViewById<Button>(R.id.btn_cancel)?.setOnClickListener { dismiss() }
        mView?.findViewById<Button>(R.id.btn_ok)?.setOnClickListener { dismiss(); setValue() }
    }

    private fun setValue() {
        valueBack(mView?.findViewById<EditText>(R.id.et_value)?.text.toString())
    }

}